<script lang="ts">
import { defineComponent } from 'vue';
let payFromType = '';
// #ifdef SUBSCRIPTION || PRIVATE
payFromType = 'mp';
// #endif
// #ifdef APP
payFromType = 'app';
// #endif
// #ifdef HTML5 || PREVIEW
payFromType = 'H5';
// #endif
// #ifdef MP-WEIXIN
payFromType = 'miniapp';
// #endif
// #ifdef MP-ALIPAY
payFromType = 'alimapp';
// #endif
export default defineComponent({
	globalData: {
		host: '',
		cssPrimaryColor: 'rgba(255, 255, 255, 1)',
		// 支付的环境类型
		payFromType
	}
});
</script>

<script lang="ts" setup>
import { baseInitDispatcher } from '@/common/init';
import { useCurrentInstance } from '@/common/hooks';
import { useUser, useShoppingCart, useInit, useIM, useBasics } from '@/common/stores';
// #ifdef PRIVATE || SUBSCRIPTION
import subscriptionAndPrivateInit from '@/common/subscriptionAndPrivateInit';
// #endif
import { onHide, onShow, onLaunch } from '@dcloudio/uni-app';
import IM from '@/common/utils/IM/IM';
import type { UniGlobalData } from '@/typings/uni';
import { postSupperAppLogin } from '@/common/request/api';

const ctx = useCurrentInstance();
const { getAppConfig, setTabbarData } = useInit();


onLaunch(async () => {
	uni.removeStorageSync('userGeolocation');
	// 调用appInitComplete，代表项目已初始化完成，可以调用pinia存储相关的初始化变量
	baseInitDispatcher.appInitComplete();
	// #ifndef PRIVATE || SUBSCRIPTION
	// 除公众号与私域，其余均不为自动登录
	
	// #ifndef APP
	if (uni.getStorageSync('token')) {
		const userStores = useUser();
		const IMStore = useIM();
		userStores.getUserInfo().then((res) => {
			useShoppingCart().getCart();
			// IMStore.IMLogin(res);
		});
	} else {
		uni.removeStorageSync('userInfo');
	}
	// #endif
	
	// #ifdef APP
	uni.hideTabBar()
	// #endif
	
	
	
	
	// #endif

	// #ifdef PRIVATE || SUBSCRIPTION
	subscriptionAndPrivateInit();
	// #endif
	
	getAppConfig().then((res) => {
		setTabbarData(ctx, res);
		baseInitDispatcher.requestComplete();
	});
	console.log('App Launch');
});
onShow(() => {
	// #ifndef  MP-WEIXIN||MP-ALIPAY

	getApp<UniGlobalData>().globalData!.$t = (text: string) => {
		return ctx.$t(text);
	};
	if (!getApp<UniGlobalData>().globalData!.IM) {
		getApp<UniGlobalData>().globalData!.IM = IM;
	}
	// #endif
});
onHide(() => {});
</script>

<style lang="scss">
/*每个页面公共css */
@import 'common/css/index.scss';
@import '@/uni_modules/endless-ui/index.scss';
@import 'common/css/for.scss';
@import 'common/css/flex.scss';

/*  #ifndef  APP-NVUE  */
@import 'common/font/iconfont.css';
@import 'common/css/animation.scss';
/*  #ifndef  MP-WEIXIN||MP-ALIPAY  */
@import 'common/css/quill/quill.core.css';
/*  #endif  */
/*  #endif  */
</style>
